﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace BLL
{
    public class SanPhamBLL
    {
        ChamCongEntities chamCongEn = new ChamCongEntities();
        public class DanhSach : SanPham
        {
            public string TenHangSP { get; set; }
        }

        public List<SanPham> GetAllSanPham()
        {
            return chamCongEn.SanPhams.Include("HangSanPham").ToList<SanPham>();
        }
        public SanPham GetSanPhamById(int id)
        {
            return chamCongEn.SanPhams.Where(sp => sp.SanPhamId == id).FirstOrDefault();
        }
        public void InsertSanPham(SanPham sanPham)
        {
            chamCongEn.Entry(sanPham).State = EntityState.Added;
            chamCongEn.SaveChanges();
        }
        public void UpdateSanPham(SanPham sanPham)
        {
            chamCongEn.Entry(sanPham).State = EntityState.Modified;
            chamCongEn.SaveChanges();
        }
        public void DeleteSanPham(SanPham sanPham)
        {
            chamCongEn.Entry(sanPham).State = EntityState.Deleted;
            chamCongEn.SaveChanges();
        }
    }
}
